package com.btshop.goods.controller;
import com.btshop.goods.pojo.StockBack;
import com.btshop.goods.service.StockBackService;
import com.github.pagehelper.PageInfo;
import com.util.Result;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * @ClassName: StockBackController
 * @description: StockBack 控制层接口定义类
 * @author: 李东
 * @Date: 2020-7-20
 */
@Api(value = "StockBackController")
@Slf4j
@RestController
@RequestMapping("/stockBack")
@CrossOrigin
public class StockBackController {

    @Autowired
    private StockBackService stockBackService;

    /***
     * StockBack分页条件搜索实现
     * @param stockBack
     * @param page
     * @param size
     * @return
     */
    @ApiOperation(value = "StockBack条件分页查询",notes = "分页条件查询StockBack方法详情",tags = {"StockBackController"})
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "page", value = "当前页", required = true, dataType = "Integer"),
            @ApiImplicitParam(paramType = "path", name = "size", value = "每页显示条数", required = true, dataType = "Integer")
    })
    @PostMapping(value = "/search/{page}/{size}" )
    public Result<PageInfo> findPage(@RequestBody(required = false) @ApiParam(name = "StockBack对象",value = "传入JSON数据",required = false) StockBack stockBack, @PathVariable  int page, @PathVariable  int size){
        log.info("StockBackController findPage params , stockBack : {} , page : {} , size : {}",stockBack,page,size);
        //调用StockBackService实现分页条件查询StockBack
        PageInfo<StockBack> pageInfo = stockBackService.findPage(stockBack, page, size);
        return Result.buildSuccess("查询成功！", pageInfo);
    }

    /***
     * StockBack分页搜索实现
     * @param page:当前页
     * @param size:每页显示多少条
     * @return
     */
    @ApiOperation(value = "StockBack分页查询",notes = "分页查询StockBack方法详情",tags = {"StockBackController"})
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "page", value = "当前页", required = true, dataType = "Integer"),
            @ApiImplicitParam(paramType = "path", name = "size", value = "每页显示条数", required = true, dataType = "Integer")
    })
    @GetMapping(value = "/search/{page}/{size}" )
    public Result<PageInfo> findPage(@PathVariable  int page, @PathVariable  int size){
        log.info("StockBackController findPage params , page : {} , size : {}",page,size);
        //调用StockBackService实现分页查询StockBack
        PageInfo<StockBack> pageInfo = stockBackService.findPage(page, size);
        return Result.buildSuccess("查询成功！", pageInfo);
    }

    /***
     * 多条件搜索品牌数据
     * @param stockBack
     * @return
     */
    @ApiOperation(value = "StockBack条件查询",notes = "条件查询StockBack方法详情",tags = {"StockBackController"})
    @PostMapping(value = "/search" )
    public Result<List<StockBack>> findList(@RequestBody(required = false) @ApiParam(name = "StockBack对象",value = "传入JSON数据",required = false) StockBack stockBack){
        log.info("StockBackController findList params , stockBack : {} ",stockBack);
        //调用StockBackService实现条件查询StockBack
        List<StockBack> list = stockBackService.findList(stockBack);
        return Result.buildSuccess("查询成功！", list);
    }

    /***
     * 根据主键删除品牌数据
     * @param orderId,skuId
     * @return
     */
    @ApiOperation(value = "StockBack根据主键orderId,skuId删除",notes = "根据主键删除StockBack方法详情",tags = {"StockBackController"})
    @ApiImplicitParams({
                @ApiImplicitParam(paramType = "path", name ="orderId", value = "主键", required = true, dataType = "Long"),
                @ApiImplicitParam(paramType = "path", name ="skuId", value = "主键", required = true, dataType = "Long")
    })
    @DeleteMapping(value = "/{orderId}/{skuId}")
    public Result delete(@PathVariable("orderId") Long orderId,@PathVariable("skuId") Long skuId){
        log.info("StockBackController delete params ,   orderId : {} ,   skuId : {}   ",orderId,skuId);
        //调用StockBackService实现根据主键删除
        stockBackService.delete(orderId,skuId);
        return Result.buildSuccess("删除成功！");
    }

    /***
     * 修改StockBack数据
     * @param stockBack
     * @param orderId,skuId
     * @return
     */
    @ApiOperation(value = "StockBack根据orderId,skuId修改",notes = "根据ID修改StockBack方法详情",tags = {"StockBackController"})
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name ="orderId", value = "主键", required = true, dataType = "Long"),
            @ApiImplicitParam(paramType = "path", name ="skuId", value = "主键", required = true, dataType = "Long")
     })
    @PutMapping(value="/{orderId}/{skuId}")
    public Result update(@RequestBody @ApiParam(name = "StockBack对象",value = "传入JSON数据",required = false) StockBack stockBack,@PathVariable("orderId") Long orderId,@PathVariable("skuId") Long skuId){
        log.info("StockBackController update params ,  stockBack : {},  orderId : {} ,   skuId : {}   ",stockBack,orderId,skuId);
        //设置主键值
        stockBack.setOrderId(orderId);
        stockBack.setSkuId(skuId);
        //调用StockBackService实现修改StockBack
        stockBackService.update(stockBack);
        return Result.buildSuccess("修改成功！");
    }

    /***
     * 新增StockBack数据
     * @param stockBack
     * @return
     */
    @ApiOperation(value = "StockBack添加",notes = "添加StockBack方法详情",tags = {"StockBackController"})
    @PostMapping
    public Result add(@RequestBody  @ApiParam(name = "StockBack对象",value = "传入JSON数据",required = true) StockBack stockBack){
        log.info("StockBackController add params , stockBack : {}",stockBack);
        //调用StockBackService实现添加StockBack
        stockBackService.add(stockBack);
        return Result.buildSuccess("添加成功！");
    }

    /***
     * 根据ID查询StockBack数据
     * @param orderId,skuId
     * @return
     */
    @ApiOperation(value = "StockBack根据orderId,skuId查询",notes = "根据ID查询StockBack方法详情",tags = {"StockBackController"})
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name ="orderId", value = "主键", required = true, dataType = "Long"),
            @ApiImplicitParam(paramType = "path", name ="skuId", value = "主键", required = true, dataType = "Long")
            })
    @GetMapping("/{orderId}/{skuId}")
    public Result<StockBack> findById(@PathVariable("orderId") Long orderId,@PathVariable("skuId") Long skuId){
        log.info("StockBackController findById params ,   orderId : {} ,   skuId : {}   ",orderId,skuId);
        //调用StockBackService实现根据主键查询StockBack
        StockBack stockBack = stockBackService.findById(orderId,skuId);
        return Result.buildSuccess("查询成功！",stockBack);
    }

    /***
     * 查询StockBack全部数据
     * @return
     */
    @ApiOperation(value = "查询所有StockBack",notes = "查询所StockBack有方法详情",tags = {"StockBackController"})
    @GetMapping
    public Result<List<StockBack>> findAll(){
        //调用StockBackService实现查询所有StockBack
        List<StockBack> list = stockBackService.findAll();
        return Result.buildSuccess("查询成功！",list);
    }
}
